package com.xxxx.server.controller;


import com.xxxx.server.pojo.Position;
import com.xxxx.server.pojo.ResBean;
import com.xxxx.server.service.IPositionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Wrapper;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2021-10-28
 */
@RestController
@RequestMapping("/system/basic/pos")
public class PositionController {
    @Autowired
    private IPositionService iPositionService;

@ApiOperation(value="获取所有职位信息")
    @GetMapping("/")
    public List<Position> getPosition(){
        return iPositionService.getPosition();
//    return iPositionService.list();mabits-plus封装好的，service，mapper都不用写的
    }

@ApiOperation(value = "添加职位信息")
    @PostMapping("/")
public ResBean addPosition(@RequestBody Position position) {
    position.setCreateDate(LocalDateTime.now());
    if (iPositionService.save(position))
        return ResBean.success("添加成功!");
    else
        return ResBean.error("添加失败！");
}
@ApiOperation(value = "更新职位信息")
    @PutMapping("/")
    public ResBean updatePosition(@RequestBody Position position){
    if(iPositionService.updateById(position))
        return ResBean.success("更新成功！");
    else
        return ResBean.error("更新失败！");
}

@ApiOperation(value = "删除职位信息")
    @DeleteMapping("/{id}")
    public  ResBean deletePosition(@PathVariable Integer id){
    if(iPositionService.removeById(id))
        return ResBean.success("删除成功！");
    else
        return ResBean.error("删除失败！");
}
@ApiOperation(value="批量删除职位信息")
    @DeleteMapping("/")
    public ResBean deletePositionByIds(Integer[] ids){
    if(iPositionService.removeByIds(Arrays.asList(ids)))
        return ResBean.success("删除成功！");
    else
        return ResBean.error("删除失败！");
}


}
